﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace HigLabo.WindowsAzure.RestService.ServiceManagement
{
    public class UpgradeDeploymentBody
    {
        public UpgradeDeploymentMode Mode { get; private set; }
        public String PackageUrl { get; private set; }
        public String Configuration { get; private set; }
        public String Label { get; private set; }
        public String RoleToUpgrade { get; private set; }
        public Boolean Force { get; private set; }

        public UpgradeDeploymentBody
            (UpgradeDeploymentMode mode,
            String packageUrl,
            String configuration,
            String label,
            String roleToUpgrade,
            Boolean force)
        {
            this.Mode = mode;
            this.PackageUrl = packageUrl;
            this.Label = label;
            this.Configuration = configuration;
            this.RoleToUpgrade = roleToUpgrade;
            this.Force = force;
        }
        public String CreateText()
        {
            var ns = XNamespace.Get("http://schemas.microsoft.com/windowsazure");
            var doc = new XDocument();
            var root = new XElement(ns.GetName("UpgradeDeployment"));
            doc.Add(root);
            root.Add(new XElement(ns.GetName("Mode"), this.Mode == UpgradeDeploymentMode.Auto ? "auto" : "manual"));
            root.Add(new XElement(ns.GetName("PackageUrl"), this.PackageUrl));
            root.Add(new XElement(ns.GetName("Configuration"), Base64Converter.To(this.Configuration)));
            root.Add(new XElement(ns.GetName("Label"), Base64Converter.To(this.Label)));
            root.Add(new XElement(ns.GetName("RoleToUpgrade"), this.RoleToUpgrade));
            root.Add(new XElement(ns.GetName("Force"), this.Force ? "true" : "false"));
            return doc.ToString();
        }
        

    }
}
